/*
 * Copyright (C), 2015-2019
 * FileName: ConstantInfoMethodref
 * Author:   lizhao
 * Date:     2019-02-11 15:22
 * Description: 方法的符号引用 u1+u2+u2
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.lizhaoblog.jjvm.classfile.constantpool.impl;

import com.lizhaoblog.jjvm.classfile.ClassReader;
import com.lizhaoblog.jjvm.classfile.constantpool.BaseConstantInfo;
import com.lizhaoblog.jjvm.classfile.constantpool.ConstantInfo;
import com.lizhaoblog.jjvm.classfile.constantpool.ConstantPool;

/**
 * 〈一句话功能简述〉<br>
 * 〈方法的符号引用 u1+u2+u2〉
 *
 * @author lizhao
 * @date 2019-02-11 15:22
 * @since 1.0.0
 */
public class ConstantInfoMethodref extends BaseConstantInfo implements ConstantInfo {
    private ConstantPool constantPool;
    private int classIndex; // 类索引 u2
    private int nameAndTypeIndex;// 方法索引 u2

    public ConstantInfoMethodref(ConstantPool constantPool, ClassReader reader) {
        this.constantPool = constantPool;
        this.classIndex = reader.nextU2ToInt();
        this.nameAndTypeIndex = reader.nextU2ToInt();
    }

    @Override
    public String getValue() {
        value = constantPool.getUtfStringByIndex(classIndex) + "." + constantPool.getUtfStringByIndex(nameAndTypeIndex);
        return super.getValue();
    }
}
